﻿using ReactiveUI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RFID_EnergyTeam.ViewModel
{
    public class MainViewModel : ReactiveUI.ReactiveObject
    {
        string carNo;
        public string CarNo
        {
            get
            {
                return carNo;
            }
            set  //DependencyProperty coding
            {
                this.RaiseAndSetIfChanged(ref carNo, value);
            }
        }


        string lblTime;
        public string LblTime
        {
            get

            {
                return lblTime;
            }
            set  //DependencyProperty coding
            {
                this.RaiseAndSetIfChanged(ref lblTime, value);

            }
        }

        string outText;
        public string OutText
        {
            get
            {
                return outText;
            }
            set  //DependencyProperty coding
            {
                this.RaiseAndSetIfChanged(ref outText, value);

            }
        }


        ListBox lst;
        public ListBox Lst
        {
            get
            {
                return lst;
            }
            set  //DependencyProperty coding
            {
                this.RaiseAndSetIfChanged(ref lst, value);

            }
        }

        public ReactiveCommand<object> AddingText { get; private set; }
        public ReactiveCommand<object> AddingItem { get; private set; }

        public MainViewModel()
        {
            
            
            var btnClickOperation = this.WhenAny(vm => vm.CarNo,
                 s => !string.IsNullOrWhiteSpace(s.Value));
            AddingText = ReactiveCommand.Create(btnClickOperation);
            AddingText.Subscribe(_ =>
                    OutText = "입차 → [" + CarNo + "] 차량이 " + lblTime + " 에 입차하였습니다."                  
                 );

            var btnClickOperation2 = this.WhenAny(vm => vm.OutText,
                s => !string.IsNullOrWhiteSpace(s.Value));
            AddingItem = ReactiveCommand.Create(btnClickOperation2);
            AddingItem.Subscribe(OutText=>Lst.Items.Add("ssd"));
        }
    }
}
